﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class SetDefaultIcon  {
	static public void DoSetIcon(string iconPath){
		Texture2D icon = ReadIconFile(iconPath);
		SetPlayserSettingIcons(icon);
	}

 	static public Texture2D ReadIconFile (string path)
	{
		Texture2D inputTexture = (Texture2D)Resources.Load(path, typeof(Texture2D)) as Texture2D;
		return inputTexture;
//		WWW w = new WWW (path);
//		while (!w.isDone) { }
//
//		Texture2D icon = null;
//		if (w.error == null) {
//			icon = w.texture;
//		} else {
//			Debug.LogError("Read " + path + " Error: " + w.error.ToString ());
//		}
//
//		w.Dispose (); // free www object
//		w = null;
//
//		return icon;
	}
	
	static public void SetPlayserSettingIcons(Texture2D icon){
		int[] sizes = PlayerSettings.GetIconSizesForTargetGroup(BuildTargetGroup.Android);

		Texture2D[] icons = new Texture2D[sizes.Length];
		for (int i = 0; i < icons.Length; ++i) {
			icons[i]=icon;
		}
      	PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, icons); 
	}
}
